<?php

require_once 'common/conn.php';
$result = array();

if (isset($_GET['usercode'])) {
    $usercode = $_GET['usercode'];
}

if (isset($_GET['birthday'])) {
    $birthday = $_GET['birthday'];
}

if (isset($_GET['sex'])) {
    $sex = $_GET['sex'];
}
if (isset($_GET['nickname'])) {
    $nickname = $_GET['nickname'];
}

if (isset($usercode)) {
    $usercode = trim($usercode);
    if (isset($birthday)) {
        $birthday = trim($birthday);
        $birthday = "birthday = '" . $birthday . "',";
    } else {
        $birthday = "";
    }

    if (isset($sex)) {
        $sex = trim($sex);
        $sex = "sex = " . $sex . ",";
    } else {
        $sex = "";
    }

    if (isset($nickname)) {
        $nickname = trim($nickname);
        $nickname = "nickname = " . $nickname . ",";
    } else {
        $nickname = "";
    }

    $sql = "UPDATE t_device SET " . $nickname . $birthday . $sex . "devicecode = '" . $usercode . "' WHERE devicecode = '" . $usercode . "'";

    $db = new DBC();

    if ($db->execute($sql)) {
        $result['errorNo'] = 0;
    } else {
        $result['errorNo'] = 1;
    }
} else {
    $result['errorNo'] = 1;
}

echo json_encode($result);
?>
